package com.CNMedical.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.diboot.core.service.impl.BaseServiceImpl;
import com.CNMedical.common.utils.DateUtils;
import com.CNMedical.system.domain.vo.AppletForumCollectVO;
import org.springframework.stereotype.Service;
import com.CNMedical.system.mapper.AppletForumCollectMapper;
import com.CNMedical.system.domain.entity.AppletForumCollect;
import com.CNMedical.system.service.IAppletForumCollectService;

import javax.annotation.Resource;

/**
 * 论坛帖子收藏Service业务层处理
 * 
 * @author tang
 * @date 2023-04-01
 */
@Service
public class AppletForumCollectServiceImpl extends BaseServiceImpl<AppletForumCollectMapper, AppletForumCollect> implements IAppletForumCollectService
{
    @Resource
    private AppletForumCollectMapper appletForumCollectMapper;

    @Override
    public Boolean checkWhetherCollect(String forumId, String userId) {
        return lambdaQuery().eq(AppletForumCollect::getForumId,forumId)
                .eq(AppletForumCollect::getUserId,userId).exists();
    }

    @Override
    public List<AppletForumCollectVO> getForumCollectListByUserId(String userId) {
        List<AppletForumCollectVO> appletForumCollectVOList = getViewObjectList(Wrappers.lambdaQuery(AppletForumCollect.class)
                        .eq(AppletForumCollect::getUserId, userId),
                null,
                AppletForumCollectVO.class);
        return appletForumCollectVOList;
    }

    @Override
    public Boolean cancelForumCollect(AppletForumCollect appletForumCollect) {
        return lambdaUpdate().eq(AppletForumCollect::getForumId,appletForumCollect.getForumId())
                .eq(AppletForumCollect::getUserId,appletForumCollect.getUserId())
                .remove();
    }

    /**
     * 查询论坛帖子收藏
     * 
     * @param id 论坛帖子收藏主键
     * @return 论坛帖子收藏
     */
    @Override
    public AppletForumCollect selectAppletForumCollectById(Long id)
    {
        return appletForumCollectMapper.selectAppletForumCollectById(id);
    }

    /**
     * 查询论坛帖子收藏列表
     * 
     * @param appletForumCollect 论坛帖子收藏
     * @return 论坛帖子收藏
     */
    @Override
    public List<AppletForumCollect> selectAppletForumCollectList(AppletForumCollect appletForumCollect)
    {
        return appletForumCollectMapper.selectAppletForumCollectList(appletForumCollect);
    }

    /**
     * 新增论坛帖子收藏
     * 
     * @param appletForumCollect 论坛帖子收藏
     * @return 结果
     */
    @Override
    public int insertAppletForumCollect(AppletForumCollect appletForumCollect)
    {
        appletForumCollect.setCreateTime(DateUtils.getNowDate());
        return appletForumCollectMapper.insertAppletForumCollect(appletForumCollect);
    }

    /**
     * 修改论坛帖子收藏
     * 
     * @param appletForumCollect 论坛帖子收藏
     * @return 结果
     */
    @Override
    public int updateAppletForumCollect(AppletForumCollect appletForumCollect)
    {
        appletForumCollect.setUpdateTime(DateUtils.getNowDate());
        return appletForumCollectMapper.updateAppletForumCollect(appletForumCollect);
    }

    /**
     * 批量删除论坛帖子收藏
     * 
     * @param ids 需要删除的论坛帖子收藏主键
     * @return 结果
     */
    @Override
    public Boolean deleteAppletForumCollectByIds(Long[] ids)
    {
        return lambdaUpdate().in(AppletForumCollect::getId,ids).remove();
//        return appletForumCollectMapper.deleteAppletForumCollectByIds(ids);
    }

    /**
     * 删除论坛帖子收藏信息
     * 
     * @param id 论坛帖子收藏主键
     * @return 结果
     */
    @Override
    public int deleteAppletForumCollectById(Long id)
    {
        return appletForumCollectMapper.deleteAppletForumCollectById(id);
    }
}
